<template>
  <div>
    <el-card>
      <el-tabs v-model="activeName" @tab-click="handleClick">
        <el-tab-pane label="基本信息" name="first">
          <el-form :inline="true" style="padding-top: 30px;" :model="form" :rules="rules">
            <el-form-item label="车辆编号：" prop="truckTypeId">
              <el-input v-model="form.truckTypeId" style="width:300px" disabled />
            </el-form-item>
            <el-form-item label="车牌号码：" prop="licensePlate">
              <el-input v-model="form.licensePlate" style="width:300px" disabled />
            </el-form-item>
            <el-form-item label="车型名称：" prop="truckTypeName">
              <el-input v-model="form.truckTypeName" style="width:300px" disabled />
            </el-form-item>
            <el-form-item label="车辆体积：" prop="allowableVolume">
              <el-input v-model="form.allowableVolume" style="width:300px" disabled />
            </el-form-item>
            <el-form-item label="车辆载重：" prop="allowableLoad">
              <el-input v-model="form.allowableLoad" style="width:300px" disabled />
            </el-form-item>
            <el-form-item label="GPSID:" prop="deviceGpsId">
              <el-input v-model="form.deviceGpsId" style="width:300px" disabled />
            </el-form-item>
            <el-row>
              <el-col :span="12">
                <el-form-item label="图片信息">
                  <!-- 放置上传图片 -->
                  <div class="block">
                    <el-avatar :src="formdata.picture" :size="15*15" />
                  </div>
                </el-form-item>
              </el-col>
            </el-row>
            <div class="container"> <el-button size="medium" type="primary" style="width: 100px;">编辑</el-button></div>
          </el-form>
        </el-tab-pane>
        <el-tab-pane label="行驶证信息" name="second">
          <el-form :inline="true" style="padding-top: 30px;" :model="formdata" :rules="rules1">
            <el-form-item label="行驶证号码：" prop="transportCertificateNumber">
              <el-input v-model="formdata.transportCertificateNumber" style="width:300px" disabled />
            </el-form-item>
            <el-form-item label="发动机号码：" prop="engineNumber">
              <el-input v-model="formdata.engineNumber" style="width:300px" disabled />
            </el-form-item>
            <el-form-item label="注册时间：" prop="registrationDate">
              <el-input v-model="formdata.registrationDate" style="width:300px" disabled />
            </el-form-item>
            <el-form-item label="强制报废日期" prop="mandatoryScrap">
              <el-input v-model="formdata.mandatoryScrap" style="width:300px" disabled />
            </el-form-item>
            <el-form-item label="整备质量：" prop="overallQuality">
              <el-input v-model="formdata.overallQuality" style="width:300px" disabled />
            </el-form-item>
            <el-form-item label="检验有效期:" prop="validityPeriod">
              <el-input v-model="formdata.validityPeriod" style="width:300px" disabled />
            </el-form-item>
            <el-form-item label="核定载质量:" prop="allowableWeight">
              <el-input v-model="formdata.allowableWeight" style="width:300px" disabled />
            </el-form-item>
            <el-form-item label="有效期:" prop="expirationDate">
              <el-input v-model="formdata.expirationDate" style="width:300px; margin-right: 200px;" disabled />
            </el-form-item>

            <el-form-item label="图片信息">
              <!-- 放置上传图片 -->
              <div class="block">
                <el-avatar :src="formdata.picture" :size="15*15" />
              </div>
            </el-form-item>

          </el-form>
          <div class="container"> <el-button size="medium" type="primary" style="width: 100px;">编辑</el-button></div>
        </el-tab-pane>
      </el-tabs>
    </el-card>
  </div>
</template>

<script>
import { getcarmanager, getlicense } from '@/api/car'
export default {
  data() {
    return {
      src: '',
      value: '',
      activeName: 'first',
      form: {
        truckTypeId: '',
        licensePlate: '',
        truckTypeName: '',
        allowableVolume: '',
        allowableLoad: '',
        deviceGpsId: '',
        picture: ''
      },
      rules: {
        truckTypeId: [
          { required: true, message: '车辆编号不能为空', trigger: 'blur' }
        ],
        truckTypeName: [
          { required: true, message: '车辆类型不能为空', trigger: 'blur' }
        ],
        licensePlate: [
          { required: true, message: '车辆类型不能为空', trigger: 'blur' },
          { pattern: /^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领A-Z]{1}[A-Z]{1}[A-Z0-9]{4}[A-Z0-9挂学警港澳]{1}$/, message: '请输入正确格式的车牌号', trigger: 'blur' }
        ],
        allowableLoad: [
          { required: true, message: '应载重量不能为空', trigger: 'blur' },
          { pattern: /^(?!0)\d{1,2}$|^100$/, message: '只可输入1-100之间的整数,请重新输入', trigger: 'blur' }
        ],
        allowableVolume: [
          { required: true, message: '应载体积不能为空', trigger: 'blur' },
          { pattern: /^(?!0)\d{1,2}$|^100$/, message: '只可输入1-100之间的整数,请重新输入', trigger: 'blur' }
        ],
        deviceGpsId: [
          { required: true, message: '车辆类型不能为空', trigger: 'blur' }
        ]
      },
      formdata: {
        transportCertificateNumber: '',
        engineNumber: '',
        registrationDate: '',
        mandatoryScrap: '',
        overallQuality: '',
        validityPeriod: '',
        allowableWeight: '',
        expirationDate: ''
      },
      rules1: {
        transportCertificateNumber: [
          { required: true, message: '行驶证号码不能为空', trigger: 'blur' }
        ],
        engineNumber: [
          { required: true, message: '发动机号码不能为空', trigger: 'blur' }
        ],
        registrationDate: [
          { required: true, message: '注册时间不能为空', trigger: 'blur' }
        ],
        mandatoryScrap: [
          { required: true, message: '强制报废日期不能为空', trigger: 'blur' }
        ],
        overallQuality: [
          { required: true, message: '整备质量不能为空', trigger: 'blur' }
        ],
        validityPeriod: [
          { required: true, message: '检验有效期不能为空', trigger: 'blur' }
        ],
        allowableWeight: [
          { required: true, message: '核定载质量不能为空', trigger: 'blur' }
        ],
        expirationDate: [
          { required: true, message: '有效期不能为空', trigger: 'blur' }
        ]
      }
    }
  },
  created() {
    this.getcarmanager(this.$route.query.id)
    this.getlicense()
  },
  methods: {
    goBack() {
      window.history.back()
    },
    handleClick() {

    },
    // 更新车辆信息
    async getcarmanager(id) {
      const res = await getcarmanager(id)
      this.form = res
    },
    // 保存车辆行驶证详情
    async getlicense() {
      const msg = await getlicense(this.$route.query.id)
      this.formdata = msg
    }
  }
}

</script>

<style>
.container{
  display: flex;
  justify-content: center;
  align-items: center;

}
.avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
  }
  .avatar {
    width: 178px;
    height: 178px;

  }
</style>
